<template>
  <div>
    <Row class="header" type="flex" justify="center">
      <Col span="24">
        <Icon class="icon" type="md-pie"/>
        <span class="title">饼图</span>
      </Col>
    </Row>
    <br>
    <div id="TypesPie" :style="{ width: width + 'px', height: height + 'px'}"></div>
  </div>
</template>

<script>
import echarts from 'echarts'
// import mockData from './mockData'

export default {
  name: 'TypesCompanyPieEchart',
  data () {
    return {
      chartData: []
    }
  },
  props: {
    width: {
      type: Number,
      default: () => {
        return 300
      }
    },
    height: {
      type: Number,
      default: () => {
        return 200
      }
    }
  },
  mounted () {
    this.chart()
  },
  methods: {
    chart () {
      let option = {
        tooltip: {
          trigger: 'item'
        },
        legend: {
          textStyle: {
            fontSize: 16, // 字体大小
            color: '#ffffff'// 字体颜色
          },
          orient: 'vertical',
          // top: 'middle',
          // bottom: 10,
          left: 70,
          data: ['西凉', '益州', '兖州', '荆州']
        },
        series: [
          {
            label: {
              position: 'inner'
            },
            color: ['#ffdb5c', '#9FE6B8', '#FF9F7F', '#FB7293'],
            type: 'pie',
            radius: '80%',
            center: ['65%', '45%'],
            selectedMode: 'single',
            data: [
              { value: 535,
                name: '荆州',
                itemStyle: {
                  color: '#ff769a'
                }
              },
              { value: 510, name: '兖州' },
              { value: 634, name: '益州' },
              { value: 735, name: '西凉' }
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      }

      this.chartData.forEach(item => {
        option.dataset.source.push(item)
      })
      let myChart = echarts.init(document.getElementById('TypesPie'))
      myChart.setOption(option)
    }
  }
}
</script>

<style scoped>
  .header {
    margin-top: 10px;
    margin-left: 10px;
    height: 30px;
  }

  .icon {
    color: #d7f5ff;
    font-size: 28px;
    font-weight: 600;
    margin-right: 5px;
  }
  .title {
    color: #d7f5ff;
    font-size: 16px;
    font-weight: 600;
    line-height: 30px;
  }
</style>
